﻿using System;

class MethodReadNumber
{
    
    static void Main()
    {
        //Exercise 2.
        //Write a method ReadNumber(int start, int end) that enters an integer number in given range [start...end]. 
        //If an invalid number or non-number text is entered, the method should throw an exception. Using this method 
        //write a program that enters 10 numbers:
        // a1, a2, ... a10, such that 1 < a1 < ... < a10 < 100

        int start = 1;
        int end = 100;
        try
        {
            for (int i = 0; i < 10; i++)
            {
                Console.Write("Enter an integer in the range of [{0}...{1}]",start, end);
                start = ReadNumber(start, end);
            }
        }
        catch (FormatException formatException)
        {
            Console.WriteLine(formatException.Message);           
        }
        catch (ArgumentOutOfRangeException outOfRange)
        {
            Console.WriteLine(outOfRange.Message);            
        }
        catch (ArgumentException argument)
        {
            Console.WriteLine(argument.Message);
        }

    }
    public static int ReadNumber(int start, int end)
    {
        if (start > end)
        {
            throw new ArgumentException("Start is bigger than end!");
        }
        Console.Write("Enter an integer: ");
        int numberOne = int.Parse(Console.ReadLine());
        if (numberOne > end || numberOne < start)
        {
            throw new ArgumentOutOfRangeException();
        }
        return numberOne;
    }
}

